using System.Diagnostics;
using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisDimStatement : AnalysisStatement
{
    internal AnalysisDimStatement(DimStatement syntaxNode, AnalysisNode? parent) : base(AnalysisBoundKinds.DimStatement,
        syntaxNode, parent)
    {
        Syntax = syntaxNode;
    }

    private readonly List<AnalysisLocalVariable> _localVariables = [];
    
    public override int ChildrenCount => _localVariables.Count;

    public override DimStatement Syntax { get; }

    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return _localVariables;
    }

    internal override void AddChild(AnalysisNode child)
    {
        Debug.Assert(child.BoundKind == AnalysisBoundKinds.LocalVariable);
        child.Parent = this;
        _localVariables.Add((AnalysisLocalVariable)child);
    }
}

public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个Dim变量声明语句
    /// </summary>
    /// <param name="syntaxNode">原始语法节点</param>
    /// <param name="parent">父节点，可以忽略</param>
    /// <param name="withSymbol">语法节点所在的With语句上下文类型符号</param>
    public static AnalysisDimStatement DimStatement(DimStatement syntaxNode, AnalysisNode? parent,
        ITypeSymbol? withSymbol)
    {
        return new AnalysisDimStatement(syntaxNode, parent).WithContainingWithSymbol(withSymbol);
    }
}